package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Station;
import com.share.device.domain.StationLocation;
import com.share.device.repository.StationLocationRepository;
import com.share.device.service.IStationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author YC
 */
@Tag(name = "站点接口管理")
@RestController
@RequestMapping("/station")
public class StationController extends BaseController {

    @Autowired
    private IStationService stationService;

//    @Autowired
//    private StationLocationRepository stationLocationRepository;
//    @Operation(summary = "保存站点信息到Mongodb")
//    @PostMapping("/saveStationToMongodb")
//    public void saveStationToMongodb() {
//        List<Station> list = stationService.list();
//        for (Station station : list) {
//            StationLocation stationLocation = new StationLocation();
//            // ObjectId.get() 来自MongoDB的Java驱动，用于生成MongoDB数据库中唯一的标识符（ID）
//            stationLocation.setId(ObjectId.get().toString());
//            stationLocation.setStationId(station.getId());
//            stationLocation.setLocation(new GeoJsonPoint(station.getLongitude().doubleValue(), station.getLatitude().doubleValue()));
//            stationLocation.setCreateTime(new Date());
//            stationLocationRepository.save(stationLocation);
//        }
//    }

    @Operation(summary = "分页查询站点列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Station station) {
        //设置分页参数
        startPage();
        //查询
        List<Station> list = stationService.selectStationList(station);
        return getDataTable(list);
    }

    @Operation(summary = "新增站点")
    @PostMapping
    public AjaxResult add(@RequestBody Station station) {
        return toAjax(stationService.saveStation(station));
    }

    @Operation(summary = "修改站点")
    @PutMapping
    public AjaxResult edit(@RequestBody Station station) {
        return toAjax(stationService.updateStation(station));
    }


}
